<template>
  <el-dialog title="选择车辆" :visible.sync="dialogBoole" width="65%">
    <el-form :inline="true" :model="form" class="demo-form-inline">
      <el-form-item label="车牌号:">
        <el-input v-model="form.carNo" clearable placeholder="请输入车牌号"></el-input>
      </el-form-item>
<!--      <el-form-item label="是否触发处置:">-->
<!--        <el-select v-model="form.isDisposal" clearable placeholder="请选择">-->
<!--          <el-option label="是" :value="1"/>-->
<!--          <el-option label="否" :value="2"/>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button @click="resetQuery">重置</el-button>

        <el-button type="primary" @click.stop="handleQuery">查询</el-button>
      </el-form-item>

    </el-form>

    <table-page :dataList="tableData" border :total="total" :page.sync="form.pageNum"
                :limit.sync="form.pageSize" @setSizeCurrent="handleList">
      <template slot="tableColAc">
        <el-table-column label="操作" align="center" fixed="left" width="100">
          <template #default="{row}">
            <el-button size="mini" type="text" @click="handleSelect(row)">
              选择车辆
            </el-button>
          </template>
        </el-table-column>
      </template>

      <template slot="tableCol">
        <el-table-column label="车牌号" prop="carNo" show-overflow-tooltip align="center"/>

        <el-table-column label="车架号" prop="vinNo" show-overflow-tooltip align="center"/>

        <el-table-column label="品牌/车型/车款" show-overflow-tooltip align="center">
          <template #default="{row}">
            {{ row.brandName }}/{{ row.modelName }}/{{ row.seriesName }}
          </template>
        </el-table-column>

        <el-table-column label="车辆产权" prop="propertyRightName" show-overflow-tooltip align="center"/>

        <el-table-column label="登记日期" show-overflow-tooltip align="center">
          <template #default="{row}">
            {{ row.registerTime ? $dayjs(row.registerTime).format('YYYY-MM-DD') : '' }}
          </template>
        </el-table-column>

        <el-table-column label="车龄" prop="carAge" show-overflow-tooltip align="center">
          <template #default="{row}">
            <span v-if="row.isDisposal === 1" style="color: red">{{ row.carAge }}</span>
            <span v-if="row.isDisposal === 2">{{ row.carAge }}</span>
          </template>
        </el-table-column>

        <el-table-column label="在库闲置天数" prop="idleDay" align="center">
          <template #default="{row}">
            <span v-if="row.isDisposal === 1" style="color: red">{{ row.idleDay }}</span>
            <span v-if="row.isDisposal === 2">{{ row.idleDay }}</span>
          </template>
        </el-table-column>

        <el-table-column label="是否触发处置" show-overflow-tooltip align="center">
          <template #default="{row}">
            <span v-if="row.isDisposal === 1" style="color: red">是</span>
            <span v-if="row.isDisposal === 2">否</span>
          </template>
        </el-table-column>
      </template>
    </table-page>
  </el-dialog>
</template>

<script>
import {getVehicleDisposal, queryOtherList} from "@/api/vehicleDisposal/routineForewarning"

export default {
  name: "carTable",
  computed: {},
  watch: {},
  data() {
    return {
      form: {
        carNo: '',
        isDisposal: '',
        pageSize: 10,
        pageNum: 1,
      },
      total: 0,
      dialogBoole: false,
      tableData: [],
      carId: null
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    async handleSelect(row) {
      try {
        if(row.carLockType && Number(row.carLockType) === 1){
          this.$message({
            type:"warning",
            message:'当前车辆已被占用，不能进行处置操作'
          })
          return
        }
        const res = await getVehicleDisposal(row.carId)
        this.$emit('handleSelect', res?.data || {})
        this.dialogBoole = false
      } catch (e) {
        console.error(e)
      }
    },

    handleOpen() {
      this.dialogBoole = true
      this.handleList()
    },

    resetQuery() {
      this.form = {
        carNo: '',
        isDisposal: '',
        pageSize: 10,
        pageNum: 1,
      }
      this.handleList()
    },

    handleQuery() {
      this.form.pageNum = 1
      this.handleList()
    },

    async handleList() {
      try {
        const res = await queryOtherList(this.form)
        this.tableData = res.rows
        this.total = res.total
      } catch (e) {
        console.error(e)
      }

    }
  },
};
</script>

<style scoped lang=""></style>


